package com.ruoyi.electronicFence.controller;

/**
 * @author wxx
 * @description
 */

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.electronicFence.domain.EFAnalysisRequest;
import com.ruoyi.electronicFence.domain.TDeviceStatus;
import com.ruoyi.electronicFence.domain.TEfAlarmVO;
import com.ruoyi.electronicFence.service.EFAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 查询电子围栏 首页统计信息
 * @author wxx
 * @description
 * @date 2023/8/9 16:56
 *
 *
 */
@RequestMapping("/electronicFence/Analysis")
@RestController
public class EFAnalysisController extends BaseController {

    /**
     * 查询电子围栏 首页统计信息
     */


    @Autowired
    private EFAnalysisService eFAnalysisService;


    @GetMapping("/index2")
    public AjaxResult selectIndexInfo(EFAnalysisRequest eFAnalysisRequest)
    {
        Map<String, Object> map = eFAnalysisService.selectIndexInfo(eFAnalysisRequest);
        AjaxResult ajax = AjaxResult.success();
        ajax.put("data",map);
        return ajax;
    }

    @GetMapping("/index")
    public JSONObject selectIndexInfo2(EFAnalysisRequest eFAnalysisRequest)
    {
        String a= eFAnalysisService.selectIndexInfo2(eFAnalysisRequest);
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("data",a);
        ajaxResult.isSuccess();
        JSONObject json = JSONObject.parseObject(a);
        return json;
    }


    @GetMapping("/uwb/index")
    public AjaxResult selectUWBIndexInfo(TEfAlarmVO tEfAlarmVO)
    {
            AjaxResult ajaxResult = new AjaxResult();
            try{
                Map<String, Object> map = eFAnalysisService.selectUWBIndexInfo(tEfAlarmVO);
                ajaxResult.put("data",map);
                ajaxResult.put("code",200);
                ajaxResult.put("msg","查询成功");

                ajaxResult.isSuccess();
            }catch (Exception e){
                ajaxResult.put("data",null);
                ajaxResult.put("code",500);
                ajaxResult.put("msg","查询异常");

                ajaxResult.isSuccess();
            }
        return ajaxResult;


    }
    @GetMapping("/uwb/index2")
    public AjaxResult selectUWBIndexInfo2(TEfAlarmVO tEfAlarmVO)
    {
        Map<String, Object> map = eFAnalysisService.selectUWBIndexInfo2(tEfAlarmVO);
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("data",map);
        ajaxResult.isSuccess();
        return ajaxResult;
    }

    @GetMapping("/uwb/index3")
    public AjaxResult selectUWBIndexInfo3(TEfAlarmVO tEfAlarmVO)
    {
        Map<String, Object> map = eFAnalysisService.selectUWBIndexInfo3(tEfAlarmVO);
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("data",map);
        ajaxResult.isSuccess();
        return ajaxResult;
    }

    @GetMapping("/alarm-count-by-date")
    public AjaxResult selectAlarmCountByDate(TEfAlarmVO tEfAlarmVO)
    {
        Map<String, Object> map = eFAnalysisService.selectAlarmCountByDate(tEfAlarmVO);
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("data",map);
        ajaxResult.isSuccess();
        return ajaxResult;
    }

    @GetMapping("/device-count-by-type")
    public AjaxResult selectDeviceCountByType(TDeviceStatus tDeviceStatus)
    {
        Map<String, Object> map = eFAnalysisService.selectDeviceCountByType(tDeviceStatus);
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("data",map);
        ajaxResult.isSuccess();
        return ajaxResult;
    }

    @GetMapping("/alarm-count-by-alarm-type")
    public AjaxResult selectAlarmCountByAlarmType(TDeviceStatus tDeviceStatus)
    {
        AjaxResult ajaxResult = new AjaxResult();

        try{
            Map<String, Object> map = eFAnalysisService.selectAlarmCountByAlarmType(tDeviceStatus);
            ajaxResult.put("data",map);
            ajaxResult.put("code",200);
            ajaxResult.put("msg","查询成功");
            ajaxResult.isSuccess();
        }catch (Exception e){
            ajaxResult.put("data",null);
            ajaxResult.put("code",500);
            ajaxResult.put("msg","查询异常");
            ajaxResult.isError();
        }
        return ajaxResult;


    }


    @GetMapping("/device-count-and-alarm-count")
    public AjaxResult selectDeviceCountAndAlarmCount(TDeviceStatus tDeviceStatus)
    {
        AjaxResult ajaxResult = new AjaxResult();

        try{
           Map<String, Object> map = eFAnalysisService.selectDeviceCountAndAlarmCount(tDeviceStatus);
           ajaxResult.put("data",map);
           ajaxResult.put("code",200);
           ajaxResult.put("msg","查询成功");
           ajaxResult.isSuccess();
       }catch (Exception e){
            ajaxResult.put("data",null);
            ajaxResult.put("code",500);
            ajaxResult.put("msg","查询异常");
            ajaxResult.isError();
       }
        return ajaxResult;
    }

}
